﻿/*****************************************************
 * 本类库的核心系 JNTemplate
 * (C) JNTemplate 2011
 * 作者：翅膀的初衷 QQ:4585839
 * 网址：http://www.JiNianNet.com
 *****************************************************/
using System;
using System.Web;
using System.Collections;

namespace JinianNet.JNTemplate.Process.Common
{
    public class Cache
    {
        private static volatile System.Web.Caching.Cache cache;
        //private static object lockhelper;


        public static System.Web.Caching.Cache WebCache
        {
            get
            {
                if (cache == null)
                {
                    cache = System.Web.HttpRuntime.Cache;
                }
                return cache;
            }
        }

        public static object Get(string key)
        {
            return WebCache.Get(key);
        }
        public static void RemoveAll()
        {
            IDictionaryEnumerator CacheEnum = WebCache.GetEnumerator();
            ArrayList allKey = new ArrayList();
            while (CacheEnum.MoveNext())
            {
                allKey.Add(CacheEnum.Key);
            }

            foreach (string key in allKey)
            {
                WebCache.Remove(key);
            } 
        }
        public static void Remove(string key)
        {
            WebCache.Remove(key);
        }
        public static void Insert(string key, object value)
        {
            WebCache.Insert(key, value);
        }
    }
}
